home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Utilities Professional 1-1500
/
Utilities Professional 1-1500 (1994)(WPD)[!].iso
/
12511500
/
var1450.dms
/
var1450.adf
/
NarratorDevice
/
Example4.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-26
|
7KB
|
262 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM Devices Amiga C Club */
/* Chapter: Narrator Device Tulevagen 22 */
/* File: Example4.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-04-26 */
/* Version: 1.00 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* This example very similar to the previous one, but this */
/* time are we using a different voice. By altering the */
/* rate, pitch, mode, sex and volume, you can produce very */
/* different sounds. */
/* Declares the datatypes like STRPTR etc: */
#include <exec/types.h>
/* We are using the narrator device: */
#include <devices/narrator.h>
/* Size of the phonetic string buffer. */
#define PHONETIC_BUFFER_SIZE 200
/* The audio channels: */
/* Values: */
#define LEFT0B 0
#define RIGHT0B 1
#define RIGHT1B 2
#define LEFT1B 3
/* Bit fields: */
#define LEFT0F (1<<LEFT0B)
#define RIGHT0F (1<<RIGHT0B)
#define RIGHT1F (1<<RIGHT1B)
#define LEFT1F (1<<LEFT1B)
/* Pointer to the translator library: */
struct Library *TranslatorBase;
/* Declare a pointer to our reply port: */
struct MsgPort *replymp = NULL;
/* Declare a pointer to our narrator request block: */
struct narrator_rb *narrator_req = NULL;
/* The text should be read with all channels: */
UBYTE allocation_array[]={ LEFT0F | RIGHT0F | RIGHT1F | LEFT1F };
/* Declare our functions: */
void main();
void clean_up( STRPTR text );
void main()
{
/* Number of translated characters, or zero */
/* if all characters were translated: */
int char_translated;
/* The original string: */
char *original_string = "My darling! my love! my user!";
/* The phonetic string: */
char phonetic_string[ PHONETIC_BUFFER_SIZE ];
/* Store error values here: */
BYTE error;
/* Open the translator library: */
TranslatorBase = (struct Library *)
OpenLibrary( "translator.library", 0 );
/* Have we successfully opened the library? */
if( !TranslatorBase )
clean_up( "Could not open the translator library!" );
/* The translator library has now been opened, so */
/* we may now start to use the Translate() function. */
/* Translate our string into phonetics: (The Translate() */
/* functipon can sadly only translate English text, but */
/* with small modifications of the phonetic string it */
/* can be used with most languages.) */
char_translated =
Translate( original_string, strlen( original_string ),
phonetic_string, PHONETIC_BUFFER_SIZE );
/* If all characters could successfully be translated */
/* and stored in the phonetic string Translate() */
/* returns zero, else a negativa value is returned */
/* which tells us how many characters were actually */
/* translated: (Note that we put a minus sign infront */
/* of the variable to make it positive.) */
if( char_translated )
printf( "Translated only %d characters!\n", -char_translated );
else
printf( "All characters successfully translated!\n" );
/* Show the user what we got: */
printf( "Original string: %s\n", original_string );
printf( "Phonetic string: %s\n", phonetic_string );
/* Get a reply port: (No name, priority 0) */
replymp = (struct MsgPort *)
CreatePort( NULL, 0 );
if( !replymp )
clean_up( "Could not create the reply port!" );
/* Allocate and preinitialize a narrator request block: */
narrator_req = (struct narrator_rb *)
CreateExtIO( replymp, sizeof( struct narrator_rb ) );
if( !narrator_req )
clean_up( "Not enough memory for the narrator request!" );
/* Open the Narrator Device: */
error = OpenDevice( "narrator.device", 0, narrator_req, 0 );
if( error )
{
/* Clear the "io_Device" flag since */
/* we have not opened the device: */
narrator_req->message.io_Device = NULL;
/* Quit: */
clean_up( "Could not open the Narrator Device!" );
}
/* Set our requirements: */
/* Set the length of the phonetic string: */
narrator_req->message.io_Length = strlen( phonetic_string );
/* Give it a pointer to the phonetic string: */
narrator_req->message.io_Data = (APTR) phonetic_string;
/* Send (write) the text to the device: */
narrator_req->message.io_Command = CMD_WRITE;
/* Desired channel combinations: */
narrator_req->ch_masks = allocation_array;
/* Size of the allocation array: */
narrator_req->nm_masks = sizeof( allocation_array );
/* Use default rate: (Read 150 words per minute.) */
narrator_req->rate = DEFRATE;
/* Use a bit higher pitch than the default (110): */
narrator_req->pitch = DEFPITCH + 80;
/* Use the "natrual" voice: */
narrator_req->mode = NATURALF0;
/* An Amiga girl is reading: (Hope she is nicer than she sounds...) */
narrator_req->sex = FEMALE;
/* Use a soft (hmmm) voice: */
narrator_req->volume = MAXVOL / 2;
/* Start to read: */
SendIO( narrator_req );
/* Tell the user that the Amiga is reading: */
printf( "Computers can have emotions!\n" );
/* Wait for the narrator to finish reading the text: */
error = WaitIO( narrator_req );
/* Were there any errors? */
if( error )
{
printf( "Error code: %d\n", narrator_req->message.io_Error );
clean_up( "Error while reading!" );
}
/* Clean up and quit: */
clean_up( "The End!" );
}
/* Close and return everything that has been */
/* opened and allocated before we quit: */
void clean_up( STRPTR text )
{
/* If we have a request block and the "io_Device" field */
/* is not zero, we know that the device has successfully */
/* been opened and must now be closed: */
if( narrator_req && narrator_req->message.io_Device )
CloseDevice( narrator_req );
/* Empty the reply port: */
while( GetMsg( replymp ) )
printf( "Collected a message at the reply port.\n" );
/* Remove the replyport: */
if( replymp )
DeletePort( replymp);
/* Dealocate the narrator request block: */
if( narrator_req )
DeleteExtIO( narrator_req, sizeof( struct narrator_rb ) );
/* Close the translator library: */
if( TranslatorBase )
CloseLibrary( TranslatorBase );
/* Print the last message: */
printf( "%s\n", text );
/* Quit: */
exit( 0 );
}